package com.aishare.qicaitaoke;

import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatDelegate;

import com.aishare.qicaitaoke.db.SqliteStorage;
import com.aishare.qicaitaoke.utils.DynamicTimeFormat;
import com.aishare.qicaitaoke.utils.KLog;
import com.google.gson.Gson;
import com.orhanobut.hawk.GsonParser;
import com.orhanobut.hawk.Hawk;
import com.orhanobut.hawk.LogInterceptor;
import com.orhanobut.hawk.NoEncryption;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;

/**
 * 作者luwenming
 * 时间2018/1/31
 */

public class IApp extends Application {

    static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);//启用矢量图兼容
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @NonNull
            @Override
            public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//全局设置主题颜色
                return new ClassicsHeader(context).setTimeFormat(new DynamicTimeFormat("更新于 %s"));
            }
        });
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    private void init() {
        Hawk.init(this).setEncryption(new NoEncryption())
                .setStorage(new SqliteStorage(this))
                .setLogInterceptor(new LogInterceptor() {
                    @Override
                    public void onLog(String message) {
                        KLog.d(message + "");
                    }
                }).setParser(new GsonParser(new Gson()))
                .build();
    }
}
